# -*- coding: UTF-8 -*-
# @Time    : 2024/1/14 12:45
# @Author  : Sun
# @Email   : xxxxxxxxxxx@xxx.com
# @File    : read_six_config.py
# @software: PyCharm
# 文件注释  :
import time

import xlrd

from common.choice_file import ChoiceFile


class ReadXls:

    def __init__(self, xls_config_name: str = None):
        # print(os.getcwd())
        file_name = ChoiceFile().get_six_name()
        if xls_config_name is None:
            xls_config_name = f"../{file_name}"
        self.xls = xlrd.open_workbook(xls_config_name)

    def get_start_row(self):
        """每个表格row值不同，遍历获取"""
        number = self.xls.sheet_by_name("setting")
        row = 0
        while True:
            ret = number.row_values(rowx=row, start_colx=3, end_colx=4)
            # print(ret)
            row += 1
            if 'level' in ret:
                # print(row)
                break
        return row

    def get_reward_start_col(self):
        """动态获取商品编号列数"""
        number = self.xls.sheet_by_name("setting")
        col = 0
        while True:
            # 实际读取end_rowx列数据
            ret = number.col_values(colx=col, start_rowx=self.get_start_row() - 1, end_rowx=self.get_start_row())
            # print(ret)
            col += 1
            if '商品编号' in ret:
                # print(col)
                break
        return col

    def get_percent_start_col(self):
        """动态获取点数列数"""
        number = self.xls.sheet_by_name("setting")
        col = 0
        while True:
            # 实际读取end_rowx列数据
            ret = number.col_values(colx=col, start_rowx=self.get_start_row() - 1, end_rowx=self.get_start_row())
            # print(ret)
            col += 1
            if '获得点数' in ret:
                # print(col)
                break
        return col

    def get_price_start_col(self):
        """动态获取价格列数"""
        number = self.xls.sheet_by_name("setting")
        col = 0
        while True:
            # 实际读取end_rowx列数据
            ret = number.col_values(colx=col, start_rowx=self.get_start_row() - 1, end_rowx=self.get_start_row())
            # print(ret)
            col += 1
            if '价格/是否免费' in ret:
                # print(col)
                break
        return col

    def get_six_setting(self):
        # sheet_name = self.xls.sheet_names()
        # print(sheet_name)
        setting = self.xls.sheet_by_name("setting")
        # r = setting.row_values(rowx=70, start_colx=7, end_colx=8)  # ['T33,B29']
        # print(r)
        price_list = []
        product_list = []
        row = self.get_start_row()
        while True:
            # 商品编号获取
            reward = setting.row_values(rowx=row, start_colx=self.get_reward_start_col() - 1,
                                        end_colx=self.get_reward_start_col())  # 实际读取是第8列数据
            # 商品蓝宝石消耗值获取
            price = setting.row_values(rowx=row, start_colx=self.get_price_start_col() - 1,
                                       end_colx=self.get_price_start_col())
            # print(price)
            if reward[0] == '' or price[0] == '':
                break
            price_list.append(int(price[0]))
            product_list.append(reward[0])
            row += 1
        print(f"price_list{price_list}")
        print(f"prop_list{product_list}")
        print(f"共计{len(product_list)}级奖励")
        return [price_list, product_list]

    def get_six_percent_setting(self):
        # sheet_name = self.xls.sheet_names()
        # print(sheet_name)
        setting = self.xls.sheet_by_name("setting")
        # r = setting.row_values(rowx=70, start_colx=7, end_colx=8)  # ['T33,B29']
        # print(r)
        price_list = []
        prop_list = []
        pecent_list = []
        row = self.get_start_row()
        while True:
            # 商品编号获取
            reward = setting.row_values(rowx=row, start_colx=self.get_reward_start_col() - 1,
                                        end_colx=self.get_reward_start_col())  # 实际读取是第8列数据
            # 商品蓝宝石消耗值获取
            price = setting.row_values(rowx=row, start_colx=self.get_price_start_col() - 1,
                                       end_colx=self.get_price_start_col())
            # 每个等级给的percent
            percent = setting.row_values(rowx=row, start_colx=self.get_percent_start_col() - 1,
                                         end_colx=self.get_percent_start_col())
            # print(price)
            if reward[0] == '' or price[0] == '':
                break
            price_list.append(int(price[0]))
            prop_list.append(reward[0])
            pecent_list.append(int(percent[0]))
            row += 1
        print(f"price_list{price_list}")
        print(f"prop_list{prop_list}")
        print(f"pecent_list{pecent_list}")
        print(f"共计{len(prop_list)}级奖励")
        return [price_list, prop_list, pecent_list]

    def test(self):
        print(int(time.time()))


if __name__ == '__main__':
    ReadXls().test()
